package org.dromara.admin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 付款方式: WXPAY(微信支付), ALIPAY(支付宝支付), TRANSFER_WX(线下转账-微信), TRANSFER_ALIPAY(线下转账-支付宝), TRANSFER_BANK(线下转账-网银), WITHHOLD_MAYI(代扣:蚂蚁链)
 */
@Getter
@AllArgsConstructor
public enum PaymentMethod {

    WXPAY("WXPAY", "微信支付"),
    ALIPAY("ALIPAY", "支付宝支付"),
    TRANSFER_WX("TRANSFER_WX", "线下转账-微信"),
    TRANSFER_ALIPAY("TRANSFER_ALIPAY", "线下转账-支付宝"),
    TRANSFER_BANK("TRANSFER_BANK", "线下转账-网银"),
    WITHHOLD_MAYI("WITHHOLD_MAYI", "代扣:蚂蚁链");

    /**
     * 存库用的值
     */
    private final String code;

    /**
     * 前端展示用
     */
    private final String info;

    /**
     * 根据 code 获取枚举
     */
    public static PaymentMethod getByCode(String code) {
        for (PaymentMethod type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据 info 获取枚举
     */
    public static PaymentMethod getByInfo(String info) {
        for (PaymentMethod type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
